﻿using System.Collections.Generic;
using System.Xml.Linq;

namespace Red.Launcher.Diagnostics.Process
{
    public class Manager
    {
        #region Private Properties

        private Dictionary<string, Monitor> _monitors = new Dictionary<string, Monitor>();

        #endregion Private Properties

        #region Operator Overrides

        public Monitor this[ string name ] => _monitors[ name ];

        #endregion Operator Overrides

        #region Public Methods

        public void Load( string path )
        {
            _monitors.Clear();

            XDocument document = XDocument.Load( path );

            XElement root = document.Element( "processes" );

            foreach ( XElement process in root.Elements( "process" ) )
            {
                Definition definition = Definition.FromXml( process );
                Monitor monitor = new Monitor() { Definition = definition };
                _monitors.Add( definition.Name, monitor );
            }
        }

        #endregion Public Methods
    }
}
